# coding:utf-8

import tensorflow as tf
def read_and_decode(filename):
	# 根据文件名生成一个队列
	filename_queue = tf.train.string_input_producer([filename])
	reader = tf.TFRecordReader()
	_,serialized_example= reader.read(filename)
	features = tf.parse_single_example(serialized_example,
	                                   features={
		                                   'trY': tf.FixedLenFeature([], tf.int64),
		                                   'pixel': tf.FixedLenFeature([], tf.int64),
		                                   'trX_raw': tf.FixedLenFeature([], tf.string)})
	trX = tf.decode_raw(features['trX_raw'], tf.uint8)
	trX = tf.cast(trX, tf.float32) / 255.0
	#    trX=tf.reshape(trX,[224,224,3])
	#    print("1---------------------------------------",trX.dtype)
	trY = tf.cast(features['trY'], tf.int32)
	#    print("2",trY.dtype)
	pixel = tf.cast(features['pixel'], tf.int32)
	print(trX,trY)
# read_and_decode(r"E:\Data\Rcode\CapsNet-Tensorflow-scene-OneConv-Originimage\train.tfrecords")
import keras
from keras.applications import mobilenet_v2

mb = mobilenet_v2.MobileNetV2()
mb.save("E:\Data\Model\mob.h5")
import tensorflow as tf
import asyncio

# async def show(n):
# 	print('>>>> n <<<<')
# 	asyncio.ensure_future(lang())

# async def lang():
# 	print("--- sf ---- ")

# lp = asyncio.get_event_loop()
# asyncio.ensure_future(show(5))
# lp.run_forever()
import time
from threading import Thread
import aiohttp

def start_loop(loop):
    asyncio.set_event_loop(loop)
    loop.run_forever()

async def do_some_work(x):
    print('Waiting {}'.format(x))
    # await asyncio.sleep(1)
    asyncio.ensure_future(more_work(2))
    print('Done after {}s'.format(x))

def do():
    lp = asyncio.get_running_loop()
    asyncio.ensure_future(more_work(5),loop=lp)
async def more_work(x):
    print('More work {}'.format(x))
    time.sleep(x)
    print('Finished more work {}'.format(x))

new_loop = asyncio.new_event_loop()
t = Thread(target=start_loop, args=(new_loop,))
t.start()
# print('TIME: {}'.format(time.time() - start))

asyncio.run_coroutine_threadsafe(do_some_work(6), new_loop)
do()
# asyncio.run_coroutine_threadsafe(do_some_work(4), new_loop)
print('hello')

'''
url="https://github.com/MagicStack/uvloop/issues/2"
async def visit(url):
	async with aiohttp.ClientSession() as session:
		async with aiohttp.ClientSession() as s:
			async with s.get(url) as respo:
				res = await respo.text()
				return res
lp = asyncio.get_event_loop()
# asyncio.ensure_future(show(5))
r = lp.run_until_complete(visit(url))
print(r)
'''
'''
start = time.time()
async def do_some_work():
	await asyncio.sleep(3)
	return 3

def show(n):
	print('done after',n.result)

loop = asyncio.get_event_loop()
tasks = []
for i in range(20):
	a = asyncio.ensure_future(do_some_work())
	a.add_done_callback(show)
	tasks.append(a)
loop.run_until_complete(asyncio.gather(*tasks))
end = time.time() - start
print(end)
'''
url ="https://www.csdn.net/nav/web"
import requests
from lxml import etree
resp = requests.get(url)
content = resp.text
root = etree.HTML(content)
uls = root.xpath('//*[starts-with(@class,"feedlist_mod")]/li')
for blgs in uls:
	d = blgs.xpath("div[@class='list_con']")
	print(type(d),d[0])
	print(d[1])
	break
